<template>
    <view class="page">
        <comHead :datas="datasObj"> <template #headerContent> </template>
        </comHead>
        <view class="content_box pd-30">
            <view class="account_box bd-r40 pd-20">
                <view class="ft-28 c-33 fw-800">账号管理</view>
                <view class="list_box mt-20">
                    <view class="list_box_item" @click="openShow">
                        <view class="list_box_item_label">{{ '关联手机' }}</view>
                        <view class="list_box_item_content flex-bwt">
                            <view class="content_text">{{ userData.phone || '未关联手机' }}</view>
                            <image class="icon_samll mr-4"
                                src="https://cdn.oss.bon-top.cn/static_bc/images/icon_left.png" mode="aspectFit">
                            </image>
                        </view>
                    </view>
                    <view class="list_box_item" @click="openBind()">
                        <view class="list_box_item_label">{{ '微信绑定' }}</view>
                        <view class="list_box_item_content flex-bwt" v-if="userData.bind_wechat">
                            <view class="content_text">{{ '已绑定' }}</view>
                            <image class="icon_samll mr-4"
                                src="https://cdn.oss.bon-top.cn/static_bc/images/icon_left.png" mode="aspectFit">
                            </image>
                        </view>
                        <view class="list_box_item_content flex-bwt" v-else>
                            <view class="content_text" style="color: #1F18EE;">{{ '未绑定' }}</view>

                        </view>
                    </view>
                    <view class="list_box_item" @click="goPage('/subpackage/settings/closeAccount')">
                        <view class="list_box_item_label">{{ '注销账号' }}</view>
                        <view class="list_box_item_content flex-bwt">
                            <view class="content_text redColor">{{ '注销后无法恢复，谨慎操作' }}</view>
                            <image class="icon_samll mr-4"
                                src="https://cdn.oss.bon-top.cn/static_bc/images/icon_left.png" mode="aspectFit">
                            </image>
                        </view>
                    </view>

                </view>
            </view>
            <view class="other_box bd-r40 pd-20">
                <view class="ft-28 c-33 fw-800">其它</view>
                <view class="list_box mt-20" v-for="item in otherList" :key="item.id"
                    @click="item.url ? goPage(item.url) : ''">
                    <view class="list_box_item flex-bwt">
                        <view class="list_box_item_label">{{ item.name }}</view>
                        <image class="icon_samll mr-4" src="https://cdn.oss.bon-top.cn/static_bc/images/icon_left.png"
                            mode="aspectFit">
                        </image>

                    </view>
                </view>
                <view class="ft-22 c-99 text_center">App备案号 粤ICP备2024325860号-1X</view>

            </view>
            <view class="other_box bd-r40 pd-20">
                <view class="ft-28 c-33 fw-800">合作发展</view>
                <view class="list_box mt-20">
                    <view class="list_box_item flex-bwt">
                        <view class="list_box_item_label">{{ '合作发展联系' }}</view>
                        <image class="icon_samll mr-4" src="https://cdn.oss.bon-top.cn/static_bc/images/icon_left.png"
                            mode="aspectFit">
                        </image>

                    </view>
                </view>
            </view>
        </view>
        <view :style="{ height: (98 + 68) + 'rpx' }"></view>
        <view class="btn_box">
            <view class="box" style="height: 98rpx;">
                <view class="btn add" @click="logOut()">退出登录</view>
            </view>

        </view>
    </view>
    <!-- 删除弹窗 -->
    <view class="delete_box" ref="diaLogPop" v-if="show">
        <view class="bg"></view>
        <view class="delete_model bd-r40">
            <view class="ft-32 c-33 fw-800 mt-30">{{ '确认更换手机号？' }}</view>
            <view class="c-66 ft-28 text pd-30">
                更换后手机号 <span class="c-33 fw-800">{{ userData.phone }}</span> 将不能用于登录（180天只可更换一次）

            </view>
            <view class="btn_model flex-eve">
                <view class="btn sunbmit" @click="confirm()">确认更换</view>
                <view class="btn" @click="cancel">我再想想</view>
            </view>
        </view>
    </view>
    <!-- 微信绑定 -->
    <view class="delete_box" ref="diaLogPop" v-if="showBind">
        <view class="bg"></view>
        <view class="delete_model bd-r40">
            <view class="ft-32 c-33 fw-800 mt-30">{{ '解绑微信' }}</view>
            <view class="c-66 ft-28 text pd-30">
                解绑微信，微信“ <span class="c-33 fw-800">{{ userData.phone }}</span> ”将无法收到通知和优惠信息了，确定要解绑吗？

            </view>
            <view class="btn_model flex-eve">
                <view class="btn" @click="showBind = !showBind">取消</view>
                <view class="btn sunbmit" @click="confirmBind()">确定解绑</view>
            </view>
        </view>
    </view>

</template>
<script setup lang="js">
import comHead from '@/components/comHead.vue';
import { onLoad } from '@dcloudio/uni-app';
import { ref, reactive, getCurrentInstance } from 'vue';
import { utils } from '@/utils/utils.js';
import { api } from '@/utils/api.js';

let datasObj = reactive({
    title: '我的设置',
    img: '',
    color: '#FFFFFF',
    direction: '',
    scrollTop: 0,
    noBack: false,
    height: 88
})

const otherList = ref([
    { id: 1, name: '资质公示', key: 'experience', url: '/subpackage/rule/ruleList?name=资质公示' },
    { id: 2, name: '用户协议', key: 'service_time', url: '/subpackage/rule/ruleList?name=用户协议' },
    { id: 3, name: '隐私权政策', key: 'product_ids', url: '/subpackage/rule/ruleList?name=隐私权政策' },
    { id: 4, name: '会员服务协议', key: 'brand_id', url: '/subpackage/rule/ruleList?name=会员服务协议' },
    { id: 5, name: '关于白菜出国', key: 'brand_id', url: '/subpackage/rule/ruleList?name=关于白菜出国' },
    { id: 6, name: '意见反馈', key: 'brand_id', url: '/subpackage/settings/feedback' },
])
const logOut = () => {
    // 退出登录时 只清除token和用户信息 openid 留着做登录缓存
    uni.setStorageSync('token', '')
    uni.setStorageSync('userInfo', '')
    // uni.navigateBack(-1)
    uni.navigateTo({ url: '/pages/mine/mine' })
}
const goPage = (url) => {
    uni.navigateTo({ url: url })
}
// const goRulesPage = (item) => {
//     uni.navigateTo({ url: url })

// }
const showBind = ref(false)
const confirmBind = () => {
    utils.request(api.unbindWechat, {}, 'get').then(res => {
        if (res.code == 200) {
            showBind.value = !showBind.value
            getSettingIndex()

            uni.showToast({ title: `微信解绑成功!`, icon: 'none' })

        }
    })
}
const openBind = () => {
    if (!userData.value.bind_wechat) return
    showBind.value = !showBind.value

}
const show = ref(false)
const confirm = () => {
    userData.value.type = 'old'
    uni.navigateTo({ url: '/subpackage/settings/editPhone?data=' + JSON.stringify(userData.value) })
    show.value = !show.value
}
const openShow = () => {
    show.value = !show.value
}
const cancel = () => {
    show.value = !show.value
}
const userData = ref({})
const getSettingIndex = () => {
    utils.request(api.getSettingIndex, {}, 'get').then(res => {
        console.log('res', res)
        userData.value = res.data.info
    })
}
onLoad(() => {
    getSettingIndex()
})
</script>
<style lang="scss" scoped>
.content_box {
    border-top: 2rpx solid #F1F1F1;

    .account_box,
    .other_box {
        background-color: #F8F8F8;
        margin-bottom: 20rpx;

    }

    .account_box {
        .list_box {
            &_item {
                background-color: #fff;
                border-radius: 20rpx;
                padding: 20rpx;
                margin-bottom: 20rpx;

                &_label {
                    font-size: 24rpx;
                    color: #333;
                    font-weight: 800;

                }

                &_content {
                    margin-top: 10rpx;

                    .content_text {

                        font-size: 24rpx;
                        color: #666666;
                    }

                    .redColor {
                        color: #FF0000;
                    }
                }

            }
        }
    }

    .other_box {
        .list_box {
            &_item {
                background-color: #fff;
                border-radius: 20rpx;
                padding: 20rpx;
                margin-bottom: 20rpx;


                &_label {
                    font-size: 24rpx;
                    color: #333;
                    font-weight: 800;

                }

                &_content {
                    margin-top: 10rpx;

                    .redColor {
                        color: #FF0000;
                    }
                }

            }
        }
    }
}

.btn_box {
    width: 100%;
    position: fixed;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    background-color: #F8F8F8;
    padding-bottom: calc(10rpx + env(safe-area-inset-bottom));

    .center {
        width: 100%;
        text-align: center;
    }

    .btn_left {
        width: 132rpx;
        height: 54rpx;
        background: #FFFFFF;
        border-radius: 20rpx 20rpx 20rpx 20rpx;
        line-height: 54rpx;
        text-align: center;
    }

    .btn {
        width: 192rpx;
        height: 78rpx;
        background: #F1F1F1;
        border-radius: 20rpx 20rpx 20rpx 20rpx;
        text-align: center;
        line-height: 78rpx;
        font-size: 28rpx;

    }

    .box {
        padding: 20rpx 30rpx 0;
        box-sizing: border-box;
        height: 98rpx;


        .add {
            width: 100%;
            color: #DBF046;
            background-color: #333333;
        }

    }
}

.delete_box {
    position: fixed;
    height: 100%;
    width: 100%;
    top: 0;
    left: 0;
    z-index: 9999;


    .bg {
        position: absolute;
        height: 100%;
        width: 100%;
        background-color: #000;
        opacity: 0.5;
        top: 0;
        left: 0;
    }

    .delete_model {
        position: absolute;
        background-color: #fff;
        text-align: center;
        width: 518rpx;
        // height: 386rpx;
        top: calc(50% - (386rpx / 2));
        left: calc(50% - (518rpx / 2));

        .text {
            // padding: 20rpx;
            min-height: 140rpx;
        }

        .btn_model {
            margin-bottom: 30rpx;

            .btn {
                width: 184rpx;
                height: 80rpx;
                line-height: 80rpx;
                border-radius: 20rpx;
                font-size: 28rpx;
                color: #333;
                background-color: #F8F8F8;
            }

            .sunbmit {
                background-color: #333;
                color: #DBF046;
            }
        }
    }

}
</style>